package com.example.frn.service.impl;

import com.example.frn.dao.NewsMapper;
import com.example.frn.dto.NewsPageDto;
import com.example.frn.entity.News;
import com.example.frn.service.NewsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;
    @Override
    public boolean save(News news) {
        return newsMapper.insert(news)>0;
    }

    @Override
    public boolean updateById(News news) {
        return newsMapper.updateById(news)>0;
    }

    @Override
    public boolean removeById(Integer id) {
        return newsMapper.deleteById(id)>0;
    }

    @Override
    public News getById(Integer id) {
        return newsMapper.selectById(id);
    }

    @Override
    public PageInfo<News> page(NewsPageDto dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<News> list = newsMapper.selectList(dto.getTitle());
        return new PageInfo<>(list);
    }
}
